import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/index.vue'
import Home from '@/views/index/index.vue'
import login from '@/views/login/index.vue'
// 基础路由
const routine = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: login,
    meta: { title: '登录' }
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   children: [{
  //     path: 'index',
  //     name: 'index',
  //     component: Home,
  //     meta: { title: '首页', icon: 'iconfont iconzu925' }
  //   }]
  // },
  {
    path: '/staff',
    component: Layout,
    meta: { title: '个人信息', icon: 'iconfont icon-geren2' },
    children: [{
      path: '/staffInfo',
      name: 'staffInfo',
      component: () => import('@/views/staff/staffInfo.vue'),
      meta: { title: '个人信息' }
    },{
      path: '/changePassword',
      name: 'changePassword',
      component: () => import('@/views/staff/changePassword.vue'),
      meta: { title: '修改密码' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    meta: { title: '学生信息', icon: 'iconfont icon-yonghuziliaogerenxinxigerenziliao-xianxing' },
    children: [{
      path: '/userInfo',
      name: 'userInfo',
      component: () => import('@/views/user/userInfo.vue'),
      meta: { title: '学生信息' }
    },{
      path: '/consult',
      name: 'consult',
      component: () => import('@/views/user/consult.vue'),
      meta: { title: '学习咨询' }
    }]
  },
  {
    path: '/material',
    component: Layout,
    meta: { title: '资料信息', icon: 'iconfont icon-jieshaoxinxi_o' },
    children: [{
      path: '/myMaterial',
      name: 'myMaterial',
      component: () => import('@/views/material/myMaterial.vue'),
      meta: { title: '我的资料' }
    },{
      path: '/allMaterial',
      name: 'allMaterial',
      component: () => import('@/views/material/allMaterial.vue'),
      meta: { title: '所有资料' }
    }]
  },
  {
    path: '/course',
    component: Layout,
    meta: { title: '选课信息', icon: 'iconfont icon-xinrenkecheng' },
    children: [{
      path: '/myCourse',
      name: 'myCourse',
      component: () => import('@/views/course/myCourse.vue'),
      meta: { title: '我的课程' }
    },{
      path: '/allCourse',
      name: 'allCourse',
      component: () => import('@/views/course/allCourse.vue'),
      meta: { title: '所有课程' }
    }]
  },
  {
    path: '/exchangeInformation',
    component: Layout,
    meta: { title: '交流信息', icon: 'iconfont icon-jiaoliu' },
    children: [{
      path: '/Inbox',
      name: 'Inbox',
      component: () => import('@/views/exchangeInformation/inbox.vue'),
      meta: { title: '收件箱' }
    },{
      path: '/Outbox',
      name: 'Outbox',
      component: () => import('@/views/exchangeInformation/outbox.vue'),
      meta: { title: '发件箱' }
    }]
  },
  {
    path: '/homeworkExamination',
    component: Layout,
    meta: { title: '作业考试', icon: 'iconfont icon-kaoshizuoda' },
    children: [{
      path: '/homework',
      name: 'homework',
      component: () => import('@/views/homeworkExamination/homework.vue'),
      meta: { title: '作业信息' }
    },{
      path: '/examination',
      name: 'examination',
      component: () => import('@/views/homeworkExamination/examination.vue'),
      meta: { title: '考试信息' }
    }]
  },
]

// const error = [{ path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('@/views/404.vue') }
// ]

export const asyncRoutes = []
// 路由组合 按侧边导航顺序来
export const constantRoutes = [
  ...routine // 基础
  // ...error
]

const createRouters = () => createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // base: import.meta.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouters()

export function resetRouter() {
  const newRouter = createRouters()
  router.matcher = newRouter.matcher // reset router
}
export default router
